import argparse

# def hello(args):
#     print(f'hello, {args.name}')


# def goodbye(args):
#     print(f'goodbye, {args.name}')


# since we are now passing in the greeting
# the logic has been consolidated to a single greet function
def greet(args):
    output = '{0}, {1}!'.format(args.greeting, args.name)
    if args.caps:
        output = output.upper()
    print(output)


parser = argparse.ArgumentParser()
parser.add_argument('--version', action='version', version='1.0.0')
subparsers = parser.add_subparsers()

# With this we now have two commands (hello and goodbye)
# and a built-in help message.
#  Notice that the help message changes when run as an option on the command hello.
hello_parser = subparsers.add_parser('hello') # parse command
hello_parser.add_argument('name', help='name of the person to greet') # add the name argument
# hello_parser.set_defaults(func=hello) # set the default function to hello
# add greeting option w/ default
hello_parser.add_argument('--greeting', default='Hello', help='word to use for the greeting')
# add a flag (default=False)
hello_parser.add_argument('--caps', action='store_true', help='uppercase the output')
hello_parser.set_defaults(func=greet) # command invoke function


goodbye_parser = subparsers.add_parser("goodbye")
goodbye_parser.add_argument('name', help='name of the person to greet')
# goodbye_parser.set_defaults(func=goodbye)
goodbye_parser.add_argument('--greeting', default='Goodbye', help='word to use for the greeting')
goodbye_parser.add_argument('--caps', action='store_true', help='uppercase the output')
goodbye_parser.set_defaults(func=greet)




if __name__ == "__main__":
    args = parser.parse_args() # parse args from command line
    args.func(args) # call the default function
